home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / BasicTextAreaUI.java < prev    next >
Text File  |  1998-06-30  |  4KB  |  116 lines

  1. /*
  2.  * @(#)BasicTextAreaUI.java    1.52 98/04/09
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package com.sun.java.swing.plaf.basic;
  21.  
  22. import java.beans.*;
  23. import java.awt.*;
  24. import java.awt.event.KeyEvent;
  25. import java.awt.event.InputEvent;
  26. import com.sun.java.swing.*;
  27. import com.sun.java.swing.text.*;
  28. import com.sun.java.swing.plaf.*;
  29.  
  30. /**
  31.  * Provides the look and feel for a plain text editor.  In this
  32.  * implementation the default UI is extended to act as a simple
  33.  * view factory.
  34.  * <p>
  35.  * Warning: serialized objects of this class will not be compatible with
  36.  * future swing releases.  The current serialization support is appropriate
  37.  * for short term storage or RMI between Swing1.0 applications.  It will
  38.  * not be possible to load serialized Swing1.0 objects with future releases
  39.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  40.  * baseline for the serialized form of Swing objects.
  41.  *
  42.  * @author  Timothy Prinzing
  43.  * @version 1.52 04/09/98
  44.  */
  45. public class BasicTextAreaUI extends BasicTextUI {
  46.  
  47.     /**
  48.      * Creates a UI for a JTextArea.
  49.      *
  50.      * @param ta a text area
  51.      * @return the UI
  52.      */
  53.     public static ComponentUI createUI(JComponent ta) {
  54.         return new BasicTextAreaUI();
  55.     }
  56.  
  57.     /**
  58.      * Constructs a new BasicTextAreaUI object.
  59.      */
  60.     public BasicTextAreaUI() {
  61.     super();
  62.     }
  63.  
  64.     /**
  65.      * Fetches the name used as a key to look up properties through the
  66.      * UIManager.  This is used as a prefix to all the standard
  67.      * text properties.
  68.      *
  69.      * @return the name ("TextArea")
  70.      */
  71.     protected String getPropertyPrefix() {
  72.     return "TextArea";
  73.     }
  74.  
  75.     /**
  76.      * This method gets called when a bound property is changed
  77.      * on the associated JTextComponent.  This is a hook
  78.      * which UI implementations may change to reflect how the
  79.      * UI displays bound properties of JTextComponent subclasses.
  80.      * This is implemented to rebuild the View when the
  81.      * <em>WrapLine</em> or the <em>WrapStyleWord</em> property changes.
  82.      *
  83.      * @param evt the property change event
  84.      */
  85.     protected void propertyChange(PropertyChangeEvent evt) {
  86.     if (evt.getPropertyName().equals("LineWrap") ||
  87.         evt.getPropertyName().equals("WrapStyleWord")) {
  88.         // rebuild the view
  89.         modelChanged();
  90.     }
  91.     }
  92.  
  93.     /**
  94.      * Creates the view for an element.  Returns a WrappedPlainView or
  95.      * PlainView.
  96.      *
  97.      * @param elem the element
  98.      * @return the view
  99.      */
  100.     public View create(Element elem) {
  101.     JTextComponent c = getComponent();
  102.     if (c instanceof JTextArea) {
  103.         JTextArea area = (JTextArea) c;
  104.         View v;
  105.         if (area.getLineWrap()) {
  106.         v = new WrappedPlainView(elem, area.getWrapStyleWord());
  107.         } else {
  108.         v = new PlainView(elem);
  109.         }
  110.         return v;
  111.     }
  112.     return null;
  113.     }
  114.     
  115. }
  116.